<?php
$config = Yii::app()->getModuleConfig('users');
$r = array();
if($config['RBACSupport']) {
	$path = Yii::getPathOfAlias('system.web.auth') . '/schema.sql';
	if(!is_readable($path)) {
		throw new Exception("File $path not readable");
	}
	$sql = file_get_contents($path);
	$command = Yii::app()->rdb->createCommand($sql);
	$command->execute();
	$command->getPdoStatement()->closeCursor();
	$r[] = 'RBAC tables set up.';
	if($config['defaultRoles']) {
		$t2 = array();
		foreach($config['defaultRoles'] as $role) {
			call_user_func_array(array(Yii::app()->authManager,'createRole'),$role);
			$t2[] = $role[0];
		}
		$r[] = 'Default roles "'. implode('", "',$t2) . '" created.';
	}
}
else {
	$r[] = 'No RBAC support.';
}

$r[] = CHtml::link('Go to users index',array('/admin/users/index'));
$event->data = implode("<br />\n",$r);
